package com.yisu.auction.api.web.controller;

import com.yisu.auction.api.core.service.ISystemConfigService;
import com.yisu.auction.api.domain.request.BasePage;
import com.yisu.auction.api.domain.response.indexPackage.SystemConfigResponse;
import com.yisu.auction.api.domain.vo.indexPackageVos.SystemConfigVo;
import com.yisu.auction.api.web.interceptor.IAuthVerifyAnnotation;
import com.yisu.auction.ewf.common.enums.LoginTypeEnum;
import com.yisu.auction.ewf.common.web.JsonResult;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * author: 赵杰
 * Business Description： 系统参数业务
 * createTime：2017/8/16
 */
@Controller
@RequestMapping(value = "/systemConfig")
public class SystemConfigController extends BaseController {
    @Resource
    private ISystemConfigService iSystemConfigService;

    /**
     * author: 赵杰
     * Business Description：获取APP初始加载系统参数
     *
     * @param
     * @return 系统参数
     */
    @RequestMapping(value = "/getAppLoadConfig", method = {RequestMethod.POST}, produces = "application/json; charset=utf-8")
    @ResponseBody
    @IAuthVerifyAnnotation(Desc = "登录验证", LoginTypeEnum = LoginTypeEnum.NO_NEED_LOGIN)
    public JsonResult getAppLoadConfig(BasePage basePage) {
        JsonResult jsonResult = new JsonResult();
        SystemConfigResponse systemConfigResponse = new SystemConfigResponse();
        try {
            List<SystemConfigVo> systemConfigVos = iSystemConfigService.getAppLoadConfig(basePage.getAppSign());
            systemConfigResponse.setSystemConfigVos(systemConfigVos);
        } catch (Exception e) {
            logger.error("获取APP初始加载系统参数异常：" + e.getMessage());
        }
        jsonResult.setData(systemConfigResponse);
        return jsonResult;
    }


    @RequestMapping(value="/qiNiuToken", method = {RequestMethod.POST}, produces = "application/json; charset=utf-8")
    @ResponseBody
    public JsonResult getQiNiuUploadToken(BasePage basePage) {
        logger.info("get qi niu upload token");

        JsonResult result = new JsonResult();
        result.setData(iSystemConfigService.getQiNiuUploadToken());
        return result;
    }

}
